package com.ecut.xzh.controller;



import com.ecut.xzh.result.Result;
import com.ecut.xzh.service.VoucherService;
import com.ecut.xzh.vo.VoucherVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * @author XZH
 */
@RestController
@RequestMapping("/voucher")
@Slf4j
public class VoucherController {

    @Resource
    private VoucherService voucherService;

    /**
     * 获取优惠券信息
     * @return
     */
    @GetMapping("/all")
    public Result<ArrayList<VoucherVO>> getVoucher(){
        log.info("获取优惠券信息");
        ArrayList<VoucherVO> voucherVOList = voucherService.getVoucher();
        return Result.success(voucherVOList);
    }

    /**
     * 抢购优惠券
     * @param id
     * @return
     */
    @PutMapping("/buy/{id}")
    public Result buyVoucher(@PathVariable("id") Long id){
        log.info("被抢购的优惠券id：{}",id);

        return voucherService.buyVoucher(id);
    }
}
